
package cn.zl.ymcc.utils;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.dypnsapi20170525.models.*;
import com.aliyun.sdk.service.dypnsapi20170525.*;
import com.google.gson.Gson;

import darabonba.core.client.ClientOverrideConfiguration;

import net.minidev.json.JSONObject;


import java.util.*;
import java.util.concurrent.CompletableFuture;

import java.util.concurrent.ExecutionException;

public class SendSmsVerifyCode {
    public static void sendSmsVerifyCode(String phone, String code) {




        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId("LTAI5tBdQyGHKY24eVgiqKJN")
                .accessKeySecret("eI5lxZNHVeFgbs9FOPEMkOuOTvqfcO")
                .build());

        AsyncClient client = AsyncClient.builder()
                .region("cn-hangzhou") // Region ID
                .credentialsProvider(provider)
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                .setEndpointOverride("dypnsapi.aliyuncs.com")
                )
                .build();
        Map<String, String> map = new HashMap<>();
        map.put("code", code);
        map.put("min", "5");
        JSONObject jsonObject = new JSONObject(map);
        String s = jsonObject.toJSONString();
        System.out.println("-------------------------------------------------------");
        System.err.println(s);
        SendSmsVerifyCodeRequest sendSmsVerifyCodeRequest = SendSmsVerifyCodeRequest.builder()
                .signName("速通互联验证码")
                .templateCode("100001")
                .phoneNumber(phone)
                .templateParam(s)
                .build();

        CompletableFuture<SendSmsVerifyCodeResponse> response = client.sendSmsVerifyCode(sendSmsVerifyCodeRequest);
        SendSmsVerifyCodeResponse resp = null;
        try {
            resp = response.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        System.out.println(new Gson().toJson(resp));

        client.close();
    }

}
